Android 系统文件限制小探

您所在的位置:网站首页 修改android 系统文件 Android 系统文件限制小探

Android 系统文件限制小探

2024-07-05 10:48| 来源: 网络整理| 查看: 265

我们可以通过ulimit -a 用来显示当前的各种资源限制。

rk3399_all:/ # ulimit -a time(cpu-seconds) unlimited file(blocks) unlimited coredump(blocks) unlimited data(KiB) unlimited stack(KiB) 8192 lockedmem(KiB) 64 nofiles(descriptors) 1024 processes 15426 sigpending 15426 msgqueue(bytes) 819200 maxnice 40 maxrtprio 0 resident-set(KiB) unlimited address-space(KiB) unlimited

在Linux系统中,每个进程可以使用的FD数量是有上限的,在Android中这个上限为1024,表示每个进程可以创建的file descriptors 不能超多1024个。当系统某一文件的打开句柄数超过1024时,就会报错:

"Too many open files"

那么,这个值到底是哪里定义的呢?

这边根据descriptors的属性,判断应该在kernel的某个头文件中,终于在:linux/posix_types.h 找到:

/* * This allows for 1024 file descriptors: if NR_OPEN is ever grown * beyond that you'll have to change this too. But 1024 fd's seem to be * enough even for such "real" unices like OSF/1, so hopefully this is * one limit that doesn't have to be changed [again]. * * Note that POSIX wants the FD_CLEAR(fd,fdsetp) defines to be in * (and thus ) - but this is a more logical * place for them. Solved by having dummy defines in . */ /* * This macro may have been defined in . But we always * use the one here. */ #undef __FD_SETSIZE #define __FD_SETSIZE 1024

这么说来,是否我们直接在kernel中修改这个定义,就能生效。

兴冲冲的修改了这个1024的值,编译固件测试发现:Too yong too simple.

搜索研究一通,发现在bionic/libc/kernel$ vim README.TXT 有如下一段话:

Bionic comes with a processed set of all of the uapi Linux kernel headers that can safely be included by userland applications and libraries. These clean headers are automatically generated by several scripts located in the 'bionic/kernel/tools' directory. The tools process the original unmodified kernel headers in order to get rid of many annoying declarations and constructs that usually result in compilation failure.

好吧,原来还要再经过一系列的获取,然后通过bionic/libc/kernel/tools 里面的脚本来生成。

这边验证修改:

external/kernel-headers/original/uapi$ vim linux/posix_types.h +22

#define __FD_SETSIZE 1036

然后执行工具里:

./update_all.py

再来看看:

cc@ubuntu:~/7.1/external/kernel-headers/original/uapi$ gd . diff --git a/original/uapi/linux/posix_types.h b/original/uapi/linux/posix_types.h index 988f76e..44a2fc8 100644 --- a/original/uapi/linux/posix_types.h +++ b/original/uapi/linux/posix_types.h @@ -19,7 +19,7 @@ * use the one here. */ #undef __FD_SETSIZE -#define __FD_SETSIZE 1024 +#define __FD_SETSIZE 1036

这边文件的修改是生效了。

但是,最终生成的固件,编译还是1024,也就是说,上面的修改,还是没有效果。通过了解,确认 __FD_SETSIZE 这个是用于 select 相关调用传参用的。所以修改无效。

那么,究竟在哪里可以达到修改RLIMIT_NOFILE的值呢?

通过init.rc中,我们可以发现setrlimit 语句。试试:

setrlimit nofile 1048 1048

还是无效,看看其它类似的的配置,是三个数值,那么nofile的数值是多少?

查找相关定义可以发现:

vim bionic/libc/kernel/uapi/asm-generic/resource.h

#ifndef RLIMIT_NOFILE #define RLIMIT_NOFILE 7 #endif "bioni

这样子,那在init.rc 中 加句:

setrlimit 7 1048 1048

打包生成个固件,ulimit -a 确认,生效了,真不容易。

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3